-- fromBtnRender

local ClassRef = app.mvc.createRenderClass(...)

local string_split = string.split

function ClassRef.createWithData(node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.Tips_FromBtnRender))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end
function ClassRef.create(node)
	return ClassRef.createWithData(nil, node)
end

function ClassRef:init(data)
	self.super.init(self, data)
	self:setContentSize(self._ui.Panel:getContentSize())
	self._ui.Button:setBright( false )
	self._ui.Button:setPressedActionEnabled( false )
	self._ui.Button:addClickEventListener(function()
		if 0 ~= self._featureId then
			executeFunc( self._onClick, "goto_feature", { feature = self._featureId, param = self._param} )
		end
	end)
	self:refresh()
end

--[[
	data = {funcId|str|param}
	 
	funcId = 声望商店/英雄徽章商店/光芒徽章商店/成就商店/制造，param为itemType#itemId
	funcId = 商城，param=tabidx#itemType#itemId
	funcId = 随从，param就是随从ID
	funcId = 公会，选中公会商店param={tabidx#itemType#itemId},选中帝王之路param为tabidx
	funcId = 拍卖行， param= tabIdx#auctionType#searchName
]]
function ClassRef:refresh()
	if self._data then
		self:setVisible( true )
		local data = self._data

		local tempList = string_split( data, "|" )
		self._featureId = tonumber( tempList[1] )
		self._ui.name:setString( L(tempList[2]) )
		self._param = string_split(tempList[3], "#")
		
		self._ui.Button:setBright( 0 ~= self._featureId )
	else
		self:setVisible( false )
	end
end

function ClassRef:onBtnClick( cb )
	self._onClick = cb
end

return ClassRef
